package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoCountry;
import com.muyu.danmo.service.IDanmoCountryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 国籍Controller
 * 
 * @author yangle
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/danmoCountry")
public class DanmoCountryController extends BaseController
{
    @Autowired
    private IDanmoCountryService danmoCountryService;

    /**
     * 查询国籍列表
     */
//    @RequiresPermissions("system:danmoCountry:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoCountry danmoCountry)
    {

        List<DanmoCountry> list = danmoCountryService.selectDanmoCountryList(danmoCountry);
        return Result.success(list);
    }

    /**
     * 导出国籍列表
     */
//    @RequiresPermissions("system:danmoCountry:export")
    @Log(title = "国籍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoCountry danmoCountry)
    {
        List<DanmoCountry> list = danmoCountryService.selectDanmoCountryList(danmoCountry);
        ExcelUtil<DanmoCountry> util = new ExcelUtil<DanmoCountry>(DanmoCountry.class);
        util.exportExcel(response, list, "国籍数据");
    }

    /**
     * 获取国籍详细信息
     */
//    @RequiresPermissions("system:danmoCountry:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoCountryService.selectDanmoCountryById(id));
    }

    /**
     * 新增国籍
     */
//    @RequiresPermissions("system:danmoCountry:add")
    @Log(title = "国籍", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoCountry danmoCountry)
    {
        return toAjax(danmoCountryService.insertDanmoCountry(danmoCountry));
    }

    /**
     * 修改国籍
     */
//    @RequiresPermissions("system:danmoCountry:edit")
    @Log(title = "国籍", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoCountry danmoCountry)
    {
        return toAjax(danmoCountryService.updateDanmoCountry(danmoCountry));
    }

    /**
     * 删除国籍
     */
//    @RequiresPermissions("system:danmoCountry:remove")
    @Log(title = "国籍", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoCountryService.deleteDanmoCountryByIds(ids));
    }
}
